package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.Type;
import com.drcoffee.drcoffeemall.mapper.MachineMapper;
import com.drcoffee.drcoffeemall.mapper.TypeMapper;
import com.drcoffee.drcoffeemall.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
//@DS("mysql") // yml中配置的数据源名
public class TypeServiceImpl implements TypeService {
    @Autowired
    TypeMapper typeMapper;
    @Autowired
    MachineMapper machineMapper;

    @Override
    public Map<String, Object> getTypeAll(String type_class) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            List<Type> typeList = typeMapper.getTypeAll(type_class);
            resultMap.put("result", true);
            resultMap.put("types", typeList);
            resultMap.put("message", "Success");
        } catch (Exception e) {
            resultMap.put("result", false);
            resultMap.put("type", null);
            resultMap.put("error", e.toString());
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> getType(String type_class, Integer bsh_two) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            List<Type> typeList = typeMapper.getType(type_class, bsh_two);
            resultMap.put("result", true);
            resultMap.put("types", typeList);
            resultMap.put("message", "Success");
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
            resultMap.put("type", null);
            resultMap.put("error", e.toString());
        }
        return resultMap;
    }

//    @Override
//    public Map<String, Object> getTypeById(Integer machine_id, String type_class, Integer bsh_two) {
//        Map<String, Object> resultMap = new HashMap<>();
//        try {
//            Machine machine = machineMapper.getMachineById(machine_id);
//            Type type = typeMapper.getTypeById(machine.getType_id(), type_class, bsh_two);
//            resultMap.put("result", true);
//            resultMap.put("type", type);
//            resultMap.put("message", "Success");
//        } catch (Exception e) {
//            resultMap.put("result", false);
//            resultMap.put("type", null);
//            resultMap.put("error", e.toString());
//        }
//        return resultMap;
//    }
}
